package com.example.sdk.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.example.sdk.request.OrderRequest;
import com.example.sdk.response.OrderInfoResponse;
import com.example.sdk.utils.RSAUtils;
import com.example.sdk.utils.ReturnDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.web.bind.annotation.*;


/**
 * Created by roger on 2019/1/8.
 */
@CrossOrigin
@RequestMapping(value = "/order")
@RestController
@Log4j2
@Api(value="测试",description = "测试")
public class TestController implements InitializingBean {

    @ApiOperation(value="创建订单")
    @PostMapping("createOrder")
    public ReturnDTO createOrder(OrderRequest orderRequest){
        log.info(orderRequest);
        String orderNo = System.currentTimeMillis() + "";

        OrderInfoResponse response = new OrderInfoResponse();
        response.setOrderNo(orderNo);
        response.setCustNo(orderRequest.getCustNo());
        response.setMerchTradeNo(orderRequest.getMerchTradeNo());
        response.setTradeAmt(orderRequest.getTradeAmt());
        response.setTradeType(orderRequest.getTradeType());
        ReturnDTO dto = ReturnDTO.ok2(JSON.parseObject(JSON.toJSONString(response, SerializerFeature.WriteMapNullValue)));
        dto = ReturnDTO.ok3(response, dto);
        return dto;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        RSAUtils.init();
    }
}
